
CC:=gcc
BUILD_DIR:=build/
SRC_DIR:=src/
OBJ_NAME:=main

CFLAGS= -g -Ofast
LDFLAGS = -lpthread -ldl

$(shell [ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR})
BUILD_DIR := $(shell cd $(BUILD_DIR) && /bin/pwd)
SRC_DIR := $(shell cd $(SRC_DIR) && /bin/pwd)

SRC = $(wildcard $(SRC_DIR)/*.c)
OBJ = $(patsubst $(SRC_DIR)/%.c, ${BUILD_DIR}/%.o, $(SRC))

.PHONY: build

build:$(OBJ)
	@echo LK $(BUILD_DIR)/../$(OBJ_NAME)
	@$(CC) $(CFLAGS) $(OBJ) $(LDFLAGS) -o $(BUILD_DIR)/../$(OBJ_NAME)

$(BUILD_DIR)/%.o:$(SRC_DIR)/%.c
	@echo CC $@
	@$(CC) $(CFLAGS) -c $< -o $@

.PHONY:clean
clean:
	@$(RM) -rf ${BUILD_DIR} main
